from django.template import Library

from projects.models import *
from projects import utils

register = Library()

@register.inclusion_tag("project_table.html")
def list_projects(projects):
  return {'project_list': projects.order_by('end_date', 'start_date')}

@register.inclusion_tag("workpackage_table.html")
def list_project_work_packages(project):
  set = project.workpackage_set.all()
  return {'work_package_list': set}

@register.inclusion_tag("rating.html")
def project_status(project):
  incomplete_tasks = Task.objects.filter(deliverable__objective__aim__work_package__project__id = project.id, completed_date = None)
  incomplete_deliverables = Deliverable.objects.filter(objective__aim__work_package__project__id = project.id, completed_date = None)
  objectives = Objective.objects.filter(aim__work_package__project__id = project.id)
  return utils.get_ratings("project", incomplete_tasks, incomplete_deliverables, objectives)


